<?php

/*

  Action - Attack – Prize	$0*

  +2 Cards
  Gain an Estate. Each other player gains a Curse and discards down to 3 cards in hand.

 */

class Followers extends Card implements iAction, iPrize, iAttack {

    public function __construct() {
        parent::__construct("Followers", 0);
        $this->undoPlay = false;
        $this->undoBuy = false;
    }

    public function getDescription() {
        return array(
            "+2 Cards",
            "Gain an Estate. Each other player gains a Curse and discards down to 3 cards in hand.");
    }
    
    public function play(Game $game, $isRealCard) {
        $drawed_cards = $game->drawCards(2);
        $estate = $game->moveCardFromPileToPile("Estate", BoardCards, DiscardPile);
         ScreenDisplay::addScreenMessage($game, true, "draw " . nicePrint($drawed_cards) . " and gain " . nicePrint($estate), "draws " . sizeof($drawed_cards) . " cards and gains " . ScreenDisplay::$LMSG);

        $game->setPhase(Phase_Sleep);
        $game->attack($this);

        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $curse = $game->moveCardFromPileToPile("Curse", BoardCards, DiscardPile, $name);
             ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($curse), "gains " . ScreenDisplay::$LMSG, $name);

            $playHandOther = $game->getPlayHand($name);
            $playHandSize = sizeof($playHandOther);
            if ($playHandSize > 3) {

                $cards_to_discard = $playHandSize - 3;

                $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHandOther, $cards_to_discard, $cards_to_discard, null, "Choose $cards_to_discard cards to discard", $name, true);
            }
        }

        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {
             ScreenDisplay::addScreenMessage($game, false, " and discard " . nicePrint($output), " and discards " .sizeof($output) ." cards", $name);
            
            foreach ($output as $card_name) {
                $game->moveCardFromPileToPile($card_name, PlayHand, DiscardPile, $name);
            }

            $game->setPhase(Phase_Sleep, $name);
        }
        $game->cardActionFinished();
        return true;
    }

}

?>